package 力扣日常刷题.木23一月.第04天304;

import 力扣日常刷题.ListNode;

/**
 * @author 帅小伙
 * @date 2022/3/4
 * @description
 */
public class Demo37相交链表 {


    public ListNode getIntersectionNode(ListNode headA,ListNode headB) {
        ListNode node1 = headA;
        ListNode node2 = headB;

        while(node1 != node2) {
            node1 = node1 != null ? node1.next : headB;
            node2 = node2 != null ? node2.next : headA;
        }
        return node1;
    }
}
